	
	function getCurrentUrl(lastUrl){
		if(lastUrl.indexOf("http") == 0 || lastUrl.indexOf(".") == 0 || lastUrl.indexOf("//") == 0){
			return lastUrl;
		}
		var url = window.location.href;
		url = url.substring(0,url.lastIndexOf("/"));
		return url + "/" + lastUrl;
	}
	function ajaxError(message){
		//setTimeout(function() {
    		parent.swal("出错了！", "请检查您的网络!", "error");
		//}, 1000);
	}
	function ajaxSuccess(message){
		if(message.statusCode != 0){
			parent.swal(message.title,message.message, "error");
			return false;
		}
		return true;
	}
	
	function showDialog(options){
		if((typeof options) == 'undefined'){
			options = {};
		}
		var setting = {};
		for(var temp in options){
			setting[temp] = options[temp];
		}
		var tagget = window;
		if((typeof parent) != 'undefined'){
			tagget = parent;
		}
		tagget.swal(setting, function (isConfirm) {
        	if(isConfirm && options.onConfirm){
        		options.onConfirm();
        	}else if(!isConfirm && options.onCancel){
        		options.onCancel();
        	}
        });
	}
	
	var loadingDialog;
	$(document).ajaxStart(function(){
		loadingDialog = getLayer().load(1, {time: 20*1000});
		
	}).ajaxSend(function(event,xhr,options){
		if(options.url.indexOf("?") > -1){
			options.url += "&ajax=1";
		}else{
			options.url += "?ajax=1";
		}
		
	}).ajaxComplete(function(event,xhr,options){
		//console.log(options.success);
		getLayer().close(loadingDialog);
		if(!xhr.responseJSON){
			return;
		}
		var responseJSON = xhr.responseJSON;
		if((typeof  responseJSON.statusCode ) != 'undefined' && responseJSON.statusCode != 0){
			
				if(options.onFail){
					if(options.toastMsg){
						getLayer().msg(responseJSON.message);
					}
					options.onFail(responseJSON);
				}else{
					getLayer().msg(responseJSON.message);
				}
			
		}else{
			if(options.onSuccess){
				if(options.toastMsg){
					getLayer().msg(responseJSON.message);
				}
				options.onSuccess(responseJSON);
			}else if(responseJSON.message){
				getLayer().msg(responseJSON.message);
			}
		}
	}).ajaxError(function(event,xhr,options,exc){
		//console.log(event);
		//console.log(xhr);
		//console.log(options);
		//console.log(exc);
		//console.log("ajaxError");
		if(xhr.status != 0){
			getLayer().msg("系统繁忙!");
		}else{
			getLayer().msg("请检查您的网络情况!");
		}
	});
	
	
	
	function getLayer(){
		if((typeof parent) != 'undefined' ){
			return parent.layer;
		}
		return layer;
	}